package com.server.modules.sys.scheduled;

import com.server.modules.api.service.IMService;
import com.server.modules.sys.entity.member.Member;
import com.server.modules.sys.service.member.MemberService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by 金贤哲 on 2017/3/28 0028.
 */
@Component
public class SchedulePaySuccessTask{
    @Resource
    private MemberService memberService;
    @Resource
    private IMService imService;



    @Scheduled(cron = " 0 0/1 * * * ?")
    public void successpays(){
        List<Member> successpay = memberService.paysuccess();
        if(successpay.size()!= 0) {
            Map<String, String> msg = new HashedMap();
            msg.put("type", "text");
            msg.put("msg", "客服经理您好！有客户完成产品前期缴费操作，请尽快前往后台查看！");
            List<String> userList = new ArrayList<String>(1);
            for (Member member : successpay) {
                userList.add(member.getHxUsername());
            }
//        for (int i = 0; i < userList.size(); i++) {
//           System.out.println(userList.get(i));
//        }
            imService.sendSysMessages(userList, msg, null);
        }
    }
}
